﻿namespace DeltaGroup.WheelOfJeopardy
{
    using System.Linq;
    using System.Windows;
    using System.Windows.Input;

    using DeltaGroup.WheelOfJeopardy.UI.Commands;

    /// <summary>
    /// Interaction logic for Main.xaml
    /// </summary>
    public partial class Main : Window
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Main"/> class.
        /// </summary>
        public Main()
        {
            InitializeComponent();

            this.Closed += (sender, args) => WoJCommands.Exit.Execute(this);

            var ps = from p in typeof (WoJCommands).GetFields()
                     where p.FieldType.IsSubclassOf(typeof (LoadUserControlCommand)) && p.IsStatic
                     select (LoadUserControlCommand)p.GetValue(null);

            foreach (var p in ps)
            {
                var cmd = p;
                CommandManager.RegisterClassCommandBinding(GetType(), new CommandBinding(p, (sender, e) => cmd.Load(this, e), cmd.CanExecute));
            }

            CommandManager.RegisterClassCommandBinding(GetType(), new CommandBinding(WoJCommands.Exit));
        }

        #endregion Constructors

        private void Help_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"woj\DG-WOJ-Tutorial.pdf");
        }
    }
}